﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;
using BitPortal.Models;
using BitPortal.Business;
using BitPortal.Utils;

namespace BitPortal.Admin.Config.UserConfig
{
    public partial class Default : Controls.BaseAdminPage
    {
        protected override void OnInit(EventArgs e)
        {
            PermissionBLL.CheckRoleThrowException(role:"ConfigView",useExceptionHandler:true);
            base.OnInit(e);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                BindData();
            }
        }

        protected void BindData()
        {
            this.Store1.DataSource = BitPortal.Business.PortalConfigBLL.GetByCondition(allowVisiable: true).ToList().Select(ent =>
                new { ConfigID = ent.ConfigID, Name = ent.Name, DataType = ent.DataType, Description = ent.Description, Group = ent.Group, Value = ent.GetValue().ToString() });
            this.Store1.DataBind();
        }

        protected void Store1_RefreshData(object sender, StoreRefreshDataEventArgs e)
        {
            BindData();
        }

        [DirectMethod]
        public void EditConfig(string configName)
        {
            UserConfig1.BindData(configName);
        }
    }
}